package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;


/**
 *
 *生产中心------瘦药记录
 */
@Data
public class VeterinaryDrugsReport implements Serializable{
    private static final ObjectMapper objectMapper= JsonMapper.nonEmptyMapper().getMapper();
    private static final long serialVersionUID = -3740601460226239386L;

    /**
     * id
     */

    private Long id;

    /**
     * 单据编号
     */
    private String number;

    /**
     * 状态，1：正常，-1：删除
     */
    private Integer status;

    /**
     * 养殖场id
     */
    private Long breedFactoryId;

    /**
     * 养殖场名称
     */
    private String breedFactoryName;

    /**
     * 记录日期
     */
    private Date date;

    /**
     * 养殖场区域
     */
    private Integer area;

    /**
     * 栏舍号id
     */
    private Long stableId;

    /**
     * 栏舍号
     */
    private String stableNumber;

    /**
     * 兽药名称
     */
    private String drugName;

    /**
     * 生产厂家
     */
    private String manufacturer;

    /**
     * 给药方式
     */
    private Integer useMethod;

    /**
     * 兽药照片
     */
    @JsonIgnore
    private String drugPhoto;
    /**
     * 兽药照片---不存入数据库
     */
    private Map<String,Map<String,String>> drug;

    /**
     *
     * 单据是否有效
     */
    private Integer deleteFlag;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 更新时间
     */
    private Date updatedAt;

    public void setDrugPhoto(String drugPhoto) throws Exception{
        this.drugPhoto = drugPhoto;
        if(Strings.isNullOrEmpty(drugPhoto)){
            this.drug=  Maps.newHashMap();
        } else{
            this.drug = objectMapper.readValue(drugPhoto, new TypeReference<Map<String,Map<String,String>>>(){});
        }
    }
    public void setDrug(Map<String,Map<String,String>> drug) {
        this.drug = drug;
        if(drug ==null ||drug.isEmpty()){
            this.drugPhoto = null;
        }else{
            try {
                this.drugPhoto = objectMapper.writeValueAsString(drug);
            } catch (Exception e) {
            }
        }
    }
}
